From dfccaa8831589576e081c9d6d39a5eff3b80284a Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 9 Sep 2020 15:53:09 +0200 Subject: [PATCH] revealer: Prefer min and nat size Assume that the fully expanded revealer will likely get an allocation that matches the child's minimum or natural allocation, so we special-case these two values. So when - due to the precision loss - multiple sizes would match the current allocation, we don't pick one at random, we prefer the min and nat size. The preference of nat size over min sie was decided after an IRC vote, we don't actually have an idea what's more likely to happen in the real world. Should we ever get better data, we might want to switch. --- gtk/gtkrevealer.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/gtk/gtkrevealer.c b/gtk/gtkrevealer.c index c6ac90c9ce..ee45854fb4 100644 --- a/gtk/gtkrevealer.c +++ b/gtk/gtkrevealer.c @@ -486,18 +486,39 @@ gtk_revealer_size_allocate (GtkWidget *widget, * that in large downscaling cases we may run into the clipping issue * described above. However, at these downscaling levels (100 times!) * we're unlikely to notice much detail anyway. + * + * On top, we assume that the fully expanded revealer will likely get + * an allocation that matches the child's minimum or natural allocation, + * so we special-case these two values. + * So when - due to the precision loss - multiple sizes would match + * the current allocation, we don't pick one at random, we prefer the + * min and nat size. */ if (hscale < 1.0) { + int min, nat; g_assert (vscale == 1.0); - child_width = MIN (100 * width, floor (width / hscale)); + gtk_widget_measure (priv->child, GTK_ORIENTATION_HORIZONTAL, height, &min, &nat, NULL, NULL); + if (ceil (nat * hscale) == width) + child_width = nat; + else if (ceil (min * hscale) == width) + child_width = min; + else + child_width = MIN (100 * width, floor (width / hscale)); child_height = height; } else if (vscale < 1.0) { + int min, nat; child_width = width; - child_height = MIN (100 * height, floor (height / vscale)); + gtk_widget_measure (priv->child, GTK_ORIENTATION_VERTICAL, width, &min, &nat, NULL, NULL); + if (ceil (nat * vscale) == height) + child_height = nat; + else if (ceil (min * vscale) == height) + child_height = min; + else + child_height = MIN (100 * height, floor (height / vscale)); } else { -- 2.30.2